<template>
	
	
		<view >
			
			<z-paging ref="paging"   v-model="dataList" @query="queryList" :default-page-size="10">
				<view  v-for="(item,index) in dataList" :key="index">		
				  <fui-card   :title="item.contestTitle" :tag="item.contestStatus"   >
				   <view>
				   <text>{{dateFormatter(2,item.contestStartTime)}}</text>
				   <text>{{dateFormatter(2,item.contestEndTime)}}</text>
				   <text>{{item.contestNumber}}</text>
				   <text>{{item.contestAddress}}</text>
				   </view>
				    <view v-if="item.makeres=='0'" @click="makeContest(item.id)">点击预约</view>
				  </fui-card>
				  
				 
				 </view>
			</z-paging> 
		</view>

</template>

<script>
	import utils from '@/components/firstui/fui-utils';
	export default {
		data() {
			return {
				dataList:[],
				queryForm:{
					 pageNum:1,
					pageSize:10,
					query:''
				},
				user:{},
				contestMake:{
					userId:"",
					tabContestId:""
				}
			
			}
		},
		onLoad() {
			this.user=uni.getStorageSync("user")
			if(!this.user){
				uni.switchTab({
					url: '/pages/tabbar/my/my'
				});
			}
			
		},
		methods: {
		 
		 dateFormatter(type,data) {
		 	// y-m-d h:i:s
		 	const format = ['y-m-d h:i', 'y/m/d', 'm-d', 'h:i', 'i:s', 'y年m月d日 h时i分s秒'][type - 1]
		 	const val = utils.dateFormatter(data, format);
		 	return val;
		 },
			queryList(pageNo, pageSize) {
				this.queryForm.pageNum=pageNo;
				this.queryForm.pageSize=pageSize;
				this.queryForm.query=this.user.userId;
				 this.$request.post('contest/getMakeContestList',this.queryForm).then(res => {
					 console.log()
				 	 this.$refs.paging.complete(res.data);
				 }).catch(res => {
			    	this.$refs.paging.complete(false);
			    })
			},
			makeContest(contestId){
				this.contestMake.tabContestId=contestId;
				this.contestMake.userId=this.user.userId;
			 
				this.$request.post('contestmake/saveOrUpdate',this.contestMake).then(res => {
				 	 
				 	 this.$refs.paging.reload();
				 }) 
			}
			 
		
		}
	}
</script>

<style>
  
</style>
